<?php
loadTemp("admin/models/member/member_header.php");
?>
<script type="text/javascript">
$(document).ready(function(){
	loadAdminTopItem();
	activeAdminTopItem("s_c_parent_user");
	$("#studentlist_temple").hide();
});
</script>
<?php checkAdminPermission("admin.member.parent_user","admin.class.*");?>
<!-- Start -->
<script type="text/javascript">
$(document).ready(function(){
	$("#form_parent_user_login_data").hide();
	$("#form_parent_user_profile").hide();
	bindAjaxForm($("#form_parent_user_login_data"),s_parentuser_onSuccess,s_parentuser_onError,"admin_di");
	bindAjaxForm($("#form_parent_search"),s_parentuser_onSuccess,s_parentuser_onError,"admin_di");
	bindAjaxForm($("#form_parent_user_profile"),s_parentuser_onSuccess,s_parentuser_onError,"admin_di");
	
	$(".s_master_selecter").hide();
});
function s_parentuser_onSuccess(data){
	console.log(data);
	s_parentuser_operatedone(data.code,data.message,data.data);
}
function s_parentuser_onError(data){
	console.log(data);
	s_parentuser_operatedone(-101,"服务器返回了未知的数据，请上报管理员",data.responseText);
}
function s_parentuser_operatedone(id,message,data){
	if(id==-101){
		showMessage("s_parentuser_message",-101,message+"<br><br><pre>"+data+"</pre>");
		return;
	}
	if(id!=0&&id!=3){
		showMessage("s_parentuser_message",id,message);
	}
	if(id==0){
		showMessage("s_parentuser_message",id,message);
	}
	if(data.op=="user_search"){
		$("#form_parent_search").hide();
		$(".s_uid").attr("uid",data.uid);
		console.log(data.uid);
		$.each(data.children,function(k,v){
			addChild(v);
		});
	}
	if(data.op=="remove"){
		$("#s_chi_"+data.uid).remove();
	}
}
function addChild(data){
	var $tmp = $("#studentlist_temple").clone();
	$tmp.show();
	$tmp.attr("id","s_chi_"+data.uid);
	$tmp.find(".s_name").html(data.data.name).attr("href",getHomeURL(data.data.uid));
	$tmp.find(".s_rela").html("称呼："+data.relationship);
	$tmp.find(".s_childid").attr("childid",data.data.uid);
	$tmp.find(".s_head").attr("src",data.data.head_image_path);
	$("#s_be_children_list").append($tmp);
}
function s_removerelationship(e){
	$uid = e.attr("uid");
	$childid = e.attr("childid");
	ajaxRequest("uid="+$uid+"&childid="+$childid,"admin.php?mod=member&ajax=true&op=remove_children",s_parentuser_onSuccess,s_parentuser_onError);
}
</script>
<div class="s_admin_in_container">
	<h2 class="ui dividing header">父母管理</h2>
	<div class="ui message">
		<div class="header">小提示</div>
		<ul class="list">
			<li>这里可以手动删除父母-学生的绑定</li>
		</ul>
	</div>
	<div class="ui message hidden" id="s_parentuser_message"></div>
	<form class="ui form admin_form" url="admin.php?mod=member&ajax=true&op=search_parent_user" id="form_parent_search">
		<div class="ui action fluid input">
			<div class="ui left icon input">
				<input type="text" name="account" placeholder="父母账号" id="s_parent_search">
				<i class="users icon"></i>
			</div>
			<button class="ui button submit" type="submit">确定</button>
		</div>
	</form>
	<h4 class="ui dividing header">学生列表</h4>
	<div class="ui middle relaxed aligned divided list" id="s_be_children_list"></div>
	<div class="item" id="studentlist_temple">
		<div class="right floated content">
			<a class="lm_item s_uid s_childid" onClick="s_removerelationship($(this));">解除关系</a>
		</div>
		<img class="ui avatar image s_head" src="">
		<div class="content s_description">
			<a class="s_name"></a>
			<div class="lm_item s_rela"></div>
		</div>
	</div>
</div>